﻿/*
装备出售
 */
var icon0 = "#fUI/Basic.img/VScr7/enabled/thumb0#";//小图标
var icon1 = "#fUI/ChatBalloon.img/pet/16/nw#";//小黄鸡
var icon2 = "#fUI/ChatBalloon.img/pet/16/ne#";//小黄鸡
var icon3 = "#fUI/GuildBBS/GuildBBS/Emoticon/Cash/7#";//发呆
var icon4 = "#fUI/GuildBBS/GuildBBS/Emoticon/Cash/6#";//愤怒
var icon5 = "#fUI/GuildBBS/GuildBBS/Emoticon/Cash/3#";//大笑
var icon6 = "#fUI/GuildBBS/GuildBBS/Emoticon/Cash/1#";//大笑
var status;
var text;
var itemList = new Array();
var inventoryType;
var deleteSlot;
var deleteQuantity;
var typed=0;
var beDeletedArr = new Array();
var listq = Array(
	2, 5, 10
);
var itemq = 0;

function start() {
    status = -1;
    action(1, 0, 0);
}

function action(mode, type, selection) {
    if (status == 0 && mode == 0) {
        cm.dispose();
        return;
    } else {
        if (mode == 1) {
            status++;
        } else {
            status--;
        }


				        if (status == 0) {
            var txt = "#e#b\t\t\t\t　道具分解中心#k#n\r\n\r\n";
            txt += icon1 + icon2 + icon1 + icon2 + icon1 + icon2 + icon1 + icon2 + icon1 + icon2 + icon1 + icon2 + icon1 + icon2 + icon1 + icon2 + icon1 + icon2 + "\r\n";
            txt += "　　　　 #d#L0#" + icon3 + " 分解说明    [ #r新手必看#d ]  " + icon3 + "#l#k\r\n";
            txt += "　　　　 #d#L1#" + icon6 + " 单项分解  [ #r□140-149□#d ] " + icon6 + "#l#k\r\n";
			txt += "　　　　 #d#L3#" + icon3 + " 一键分解  [ #r□140-149□#d ] " + icon3 + "#l#k\r\n";
            txt += "　　　　 #d#L2#" + icon4 + " 一键分解  [ #r□120-139□#d ] " + icon4 + "#l#k\r\n";
			//txt += "　　　　 #d#L1000#" + icon6 + " 魔方回收 [ #r□抵用回收□#d ] " + icon6 + "#l#k\r\n";
			//txt += "　　　　 #d#L1001#" + icon6 + " 石头兑换 [ #r□换成百万□#d ] " + icon6 + "#l#k\r\n";
			txt += "　　　　 #d#L999#" + icon3 + " FFN回收  [ #r□点券回收□#d ] " + icon3 + "#l#k\r\n\r\n";
			//txt += "　　　　 #d#L1000#" + icon6 + " 埃苏分解 [ #r□点券回收□#d ] " + icon6 + "#l#k\r\n\r\n";
            //txt += "　　　　 #d#L3#" + icon5 + " 回购道具 [ #r□道具□#d ] " + icon5 + "#l#k\r\n";
            
            txt += icon1 + icon2 + icon1 + icon2 + icon1 + icon2 + icon1 + icon2 + icon1 + icon2 + icon1 + icon2 + icon1 + icon2 + icon1 + icon2 + icon1 + icon2 + "\r\n\r\n";
            cm.sendSimpleS(txt, 2);
        } else if (status == 1) {
            switch (selection) {
                case 0:
                    text = icon6 + icon6 + icon6 + icon6 + icon6 + icon6 + icon6 + icon6 + icon6 + icon6 + icon6 + icon6 + icon6 + icon6 + icon6 + icon6 + icon6 + icon6 + "\r\n";
                    text += icon6 + "　　　　　　　　　　　　　　　　　　　　　　　　" + icon6 + "\r\n";
                    text += icon6 + "　　　　　　#b分解说明 -  仔细阅读 #k　　　　　　　 " + icon6 + "\r\n";
                    text += "     #d[120] 到 [139] 一键分解 #r予#d2个#v4310036#和2个#v4001713#   \r\n";
					text += "     #d[140] 到 [149] 一键每件 #r予#d5个#v4310036#和5个#v4001713#   \r\n";
                    text += "     #d[140] 到 [149] 单项分解 #r予#d5个#v4310036#和5个#v4001713#   \r\n";
					text += icon6 + "#d       每分解一个法弗纳武器可获得10W点券        " + icon6 + "\r\n";
					//text += icon6 + " #d每分解一个AS武器可获得30W点券  \t          " + icon6 + "\r\n";
				    //text += icon6 + " #e#r注：#z4000082#是制作FFN防具材料！\t    " + icon6 + "\r\n";
                    text += icon6 + "　　　　　　　　　　　　　　　　　　　　　　    " + icon6 + "\r\n";
                    text += icon6 + icon6 + icon6 + icon6 + icon6 + icon6 + icon6 + icon6 + icon6 + icon6 + icon6 + icon6 + icon6 + icon6 + icon6 + icon6 + icon6 + icon6 + "\r\n";
                    cm.sendOkS(text, 2);
                    status = -1;
                    break;
					case 999:
					cm.dispose();
											cm.openNpc(2470018,"huandian");
					break;
					case 1000:
					cm.dispose();
											cm.openNpc(2470018,"huishou1");
					break;
					case 1001:
					cm.dispose();
											cm.openNpc(2470018,"huishou2");
					break;
				case 1:
					inventoryType = 1;
					var list = cm.getInventory(inventoryType).list();
					itemList = list.iterator();
					text = "\t\t#e- 请选择要出售的装备 -#n\r\n\r\n#b";
					var indexof = 1;
					var newItemList = Array();
					while (itemList.hasNext()) {
						var item = itemList.next();
						if (cm.isCash(item.getItemId()))
							continue;
						var reqLevel = cm.getReqLevel(item.getItemId());
                        if (reqLevel < 140  ||  reqLevel > 149)
							continue;
						newItemList[item.getPosition()]=item.getItemId();
					}
					for(var key in newItemList) {
						text += "#L" + key + "##v" + newItemList[key] + "#";
						if (indexof > 1 && indexof % 5 == 0) {
							text += "\r\n";
						}
						indexof++;
					}
					typed=1;
					cm.sendSimple(text);
				break;
				case 2:
					inventoryType = 1;
					var list = cm.getInventory(inventoryType).list();
					itemList = list.iterator();
					text = "\t\t#e- 以下是准备分解的装备,请核对仔细 -#n\r\n\r\n#b";
					var indexof = 1;
					var newItemList = Array();
					while (itemList.hasNext()) {
						var item = itemList.next();
						if (cm.isCash(item.getItemId()))
							continue;
						if (item.getItemId() >= 1202001 && item.getItemId() <= 1202220 )
							continue;
							if (item.getItemId() == null)
				{
					cm.sendOk("选择的装备错误，请重新对话。");
					cm.dispose();
					return;
				}

						var reqLevel = cm.getReqLevel(item.getItemId());
						if (reqLevel >= 120 && reqLevel <140) {
							newItemList[item.getPosition()]=item.getItemId();
							beDeletedArr.push(item.getPosition());
						}
					}
					for(var key in newItemList) {
						text += "#v" + newItemList[key] + "#";
						if (indexof > 1 && indexof % 5 == 0) {
							text += "\r\n";
						}
						indexof++;
					}
					text+="\r\n#r#e分解操作不可逆，请确认是否要分解以上装备？#n#k";
					typed=2;
					cm.sendSimple(text);
				break;
				case 3:
					inventoryType = 1;
					var list = cm.getInventory(inventoryType).list();
					itemList = list.iterator();
					text = "\t\t#e- 以下是准备分解的装备,请核对仔细 -#n\r\n\r\n#b";
					var indexof = 1;
					var newItemList = Array();
					while (itemList.hasNext()) {
						var item = itemList.next();
						if (cm.isCash(item.getItemId()))
							continue;
						if (item.getItemId() >= 1202001 && item.getItemId() <= 1202220 )
							continue;
						if (item == null)
							continue;

						var reqLevel = cm.getReqLevel(item.getItemId());
						if (reqLevel >= 140 && reqLevel <149) {
							newItemList[item.getPosition()]=item.getItemId();
							beDeletedArr.push(item.getPosition());
						}
					}
					for(var key in newItemList) {
						text += "#v" + newItemList[key] + "#";
						if (indexof > 1 && indexof % 5 == 0) {
							text += "\r\n";
						}
						indexof++;
					}
					text+="\r\n#r#e分解操作不可逆，请确认是否要分解以上装备？#n#k";
					typed=3;
					cm.sendSimple(text);
				break;
			}
		} else if (status == 2) {
			if (typed==1) {
				var item = cm.getInventory(inventoryType).getItem(selection);
				if (item == null)
				{
					cm.sendOk("选择的装备错误，请重新对话。");
					cm.dispose();
					return;
				}
				deleteSlot = selection;
				deleteQuantity = item.getQuantity();
				var reqLevel = cm.getReqLevel(item.getItemId());
				itemq = getType(reqLevel);
				if (cm.getSpace(4)<2) {
					cm.sendOk("其他栏格子不足，请整理后分解。");
					cm.dispose();
					return ;
				}
				text = "#e确定要分解#r#v" + item.getItemId() + "##z" + item.getItemId() + "# " + deleteQuantity + "个 #k吗？#k";
				cm.sendSimple(text);
			} else if (typed==2) {
				itemq=2;
				var count = beDeletedArr.length*itemq;
				for(var key in beDeletedArr) {
					cm.removeSlot(1, beDeletedArr[key], 1);
				}
				cm.gainItem(4310036, count);
				cm.gainItem(4001713, count);
				text="分解成功，获得了#v4310036#和#v4001713#每种"+count+"个";
				cm.sendOk(text);
				cm.dispose();
				} else if (typed==3) {
				itemq=5;
				var count = beDeletedArr.length*itemq;
				for(var key in beDeletedArr) {
					cm.removeSlot(1, beDeletedArr[key], 1);
				}
				cm.gainItem(4310036, count);
				cm.gainItem(4001713, count);
				text="分解成功，获得了#v4310036#和#v4001713#每种"+count+"个";
				cm.sendOk(text);
				cm.dispose();
			}
		} else if (status == 3) {
			if (typed==1) {
				cm.removeSlot(inventoryType, deleteSlot, deleteQuantity);
				cm.gainItem(4001713, itemq);
				cm.gainItem(4310036, itemq);
				text="分解成功，获得了#v4310036#和#v4001713#每种"+itemq+"个";
				cm.sendOk(text);
				cm.dispose();
			}
		}
    }
}

function getType(reqLevel) {
	if (reqLevel >= 130 && reqLevel < 139) {
		return listq[0];
	} else if (reqLevel >= 140 && reqLevel < 149) {
		return listq[1];
	} else if (reqLevel >= 150 && reqLevel < 159) {
		return listq[2];
	} else {
		return 0;
	}
}